<template>
  <view class="recordInfo_container">
    <web-view :src="pdfView + url">
      <cover-view class="footer">
        <button open-type="share">
          <cover-image class="img" :src="staticUrl() + '/setting/share.png'"> </cover-image>
        </button>
      </cover-view>
    </web-view>
  </view>
</template>

<script>
import { shareInvoice } from '@/api/invoice'

export default {
  data () {
    return {
      url: '',
      pdfView: '',
      share: '',
      nativeView: ''
    }
  },
  onLoad (e) {
    shareInvoice(e.invoiceId, {
      sn: e.sn
    }).then(res => {
      if (res.code === 200) {
        this.share = res.data
      }
    })
    // if (uni.getSystemInfoSync().platform === 'android') {
    //   this.pdfView = 'https://www.xdyy100.com/pdfjs/web/viewer.html?file='
    // }
    this.pdfView = 'https://www.xdyy100.com/wholesale/files/resources/pdfjs/web/viewer.html?file='
    this.url = e.url

    // 绘制的 webview页面上层的图层
    // // #ifndef MP
    // return
    // this.nativeView = new plus.nativeObj.View('robot', {
    // 		left: 'calc(100% - 100px)',
    // 		bottom: '10px',
    // 		height: '44px',
    // 		width: '100px',
    // 		backgroundColor: 'black'

    // 	},
    // 	[{
    // 		tag: 'img',
    // 		id: 'robot',
    // 		src: '/static/setting/share.png',
    // 		position: {
    // 			top: '0px',
    // 			left: '10px',
    // 			width: '20px',
    // 			height: '20px'
    // 		}
    // 	}, ]
    // )
    // this.nativeView.show()
    // // #endif
  },
  // onUnload() {
  // 	// #ifndef MP
  // 	this.nativeView.hide()
  // 	// #endif
  // },
  onNavigationBarButtonTap () {
    uni.share({
      provider: 'weixin',
      scene: 'WXSceneSession',
      type: 1,
      summary: this.url,
      success (res) {
        console.log('success:' + JSON.stringify(res))
      },
      fail (err) {
        console.log('err:' + JSON.stringify(err))
      }
    })
  },
  methods: {
    onShareAppMessage: function () {
      let binaryString = Buffer.from(this.share.thumbData, 'base64')
      let imageUrl = `data:image/png;base64,${binaryString.toString('base64')}`
      return {
        path: `/subpackage/invoice/previewImage?url=${this.url}`,
        imageUrl: imageUrl,
        title: this.share.title,
        success: res => {
          if (res.data.code == 0) {
            uni.showToast({
              title: '转发成功',
              icon: 'success',
              mask: true
            })
          } else {
            uni.showToast({
              title: res.data.message,
              icon: 'none',
              mask: true
            })
          }
        },
        fail: err => {
          console.log('转发失败', err)
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  width: 100rpx;
  height: 100rpx;
  position: fixed;
  right: 5%;
  bottom: 8%;
  border-radius: 50%;
  z-index: 999999;
  overflow: hidden;

  button {
    background: rgba($color: #000000, $alpha: 0.5);
  }

  .img {
    width: 100%;
    height: 100%;
    margin-top: 50%;
    margin-left: 50%;
    transform: translate(-54%, -50%) scale(0.4);
  }
}
</style>
